package cn.marinda.totipotentwar.listener;

import cn.marinda.totipotentwar.TotipotentWar;
import cn.marinda.totipotentwar.global.impl.GuiImpl;
import cn.marinda.totipotentwar.runnable.GameRunnable;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;

import java.util.HashSet;
import java.util.Set;

/**
 * 库存侦听器
 *
 * @author hwj
 * @date 2022/02/05
 */
public class InventoryListener implements Listener {
    public static Set<Player> playerGame = new HashSet<>();
    private boolean onGameStart = false;
    @EventHandler
    public void onInventoryClick(InventoryClickEvent e){
        //点击的是一个玩家。
        Player player = (Player) e.getWhoClicked();
        String clickTitle = e.getClickedInventory().getTitle();
        player.sendMessage("是第：" + e.getSlot() + "格子");
        if(clickTitle.equalsIgnoreCase(GuiImpl.getGui("game").getTitle())){
            //游戏内窗体点击。 19Slot 开启游戏 22 加入游戏 25离开游戏
            if(e.getSlot() == 19){
                //开启
                player.chat("/twar start");
                player.closeInventory();
            }
            //加入游戏
            if(e.getSlot() == 22){
                player.chat("/twar join");
                player.closeInventory();
            }
            //退出游戏
            if(e.getSlot() == 25){
                player.chat("/twar leave");
                player.closeInventory();
            }
            e.setCancelled(true);
        }
        if(clickTitle.equalsIgnoreCase(GuiImpl.getGui("shop").getTitle())){
            //商店内窗体点击。
            player.sendMessage("Shop");
            e.setCancelled(true);
        }

    }


}
